package com.yuncheng.spcyApi.selectXzxkApi.api;

import com.alibaba.fastjson.JSONObject;
import com.itextpdf.text.DocumentException;
import com.yuncheng.spcyApi.config.SpcyMinioUtils;
import com.yuncheng.spcyApi.utils.LocalFileUploadUtils;
import com.yuncheng.vo.CurrentUserVo;
import com.yuncheng.vo.HttpResult;
import org.apache.commons.collections.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yuncheng.spcyApi.constant.common.BusinessConstant;
import com.yuncheng.spcyApi.constant.common.LogConstant;
import com.yuncheng.spcyApi.constant.common.SpcyConstant;
import com.yuncheng.spcyApi.constant.schedule.ScheduleConstant;
import com.yuncheng.spcyApi.constant.zwfw.ApiConstant;
import com.yuncheng.spcyApi.entity.*;
import com.yuncheng.exception.BusinessException;
import com.yuncheng.spcyApi.flow.SpcyFlowService;
import com.yuncheng.spcyApi.selectXzxkApi.vo.*;
import com.yuncheng.spcyApi.service.*;
import com.yuncheng.spcyApi.spcyService.SqsxQywjclService;
import com.yuncheng.spcyApi.utils.GetUuIdUtils;
import com.yuncheng.spcyApi.vo.common.Result;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.*;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import utils.DateConversionUtils;
import utils.LogUtils;
import utils.ObjectToMapUtils;
import utils.PdfUtils;

import javax.annotation.Resource;
import java.io.*;
import java.nio.charset.Charset;
import java.util.*;

/**
 * 智慧监管平台政务服务现场检查接口 - api
 */
@Component(value = "xzspJkApi")
public class XzspJkApi {
    private static final Logger log = LoggerFactory.getLogger(XzspJkApi.class);

    @Resource
    private ISpcyQyJbxxService spcyQyJbxxService;

    @Resource
    private ISpcySqsxBaiscService spcySqsxBaiscService;

    /*@Resource
    private ISpcySqsxWjjlService spcySqsxWjjlService;*/

    @Resource
    private ISpcyRsJlxcrwsjService jlxcrwsjService;

    @Resource
    private ISpcyLogService spcyLogService;

/*
    @Resource
    private ISpcyQyCpxxService spcyQyCpxxService;
*/

    /*@Resource
    @Lazy
    private YpscFlowService ypscFlowService;

    @Resource
    @Lazy
    private YpzcFlowService ypzcFlowService;

    @Resource
    @Lazy
    private YpltFlowService ypltFlowService;

    @Resource
    @Lazy
    private YlqxFlowService ylqxFlowService;

    @Resource
    @Lazy
    private HzpFlowService hzpFlowService;*/

    @Resource
    @Lazy
    private ISpcyScheduleJobLogService spcyScheduleJobLogService;

    @Resource
    @Lazy
    private ISpcyScheduleJobBasicService spcyScheduleJobBasicService;

    @Resource
    private ApiConstant apiConstant;

    @Resource
    @Lazy
    private SqsxQywjclService sqsxQywjclService;

    @Resource
    @Lazy
    private SpcyFlowService spcyFlowService;

    @Resource
    private SpcyMinioUtils spcyMinioUtils;

    @Resource
    private LocalFileUploadUtils localFileUploadUtils;

    /** 接口请求时间：单位毫秒
     * 套接字超时（Socket Timeout）：这个值通常设置得比连接超时稍长一些，因为数据传输可能需要更多时间。一个常见的范围是5到30秒。
     * 如果你知道服务器响应通常很快（例如，API调用返回小量数据），你可以设置得短一些。
     * 如果你的请求可能会涉及到大量数据的传输（如大文件下载），你可能需要设置得更长一些，以避免因为数据传输速度慢而导致的超时。
     * 连接超时（Connect Timeout）：
     * 通常设置为一个相对较短的时间，比如2到5秒。这是因为连接建立过程通常很快，如果服务器在这么短的时间内都无法响应连接请求，那么很可能是服务器不可达或者网络存在问题。
     * 对于需要快速响应的应用程序，你可能会想设置得更短一些。
     * 对于可能受到网络延迟影响较大的环境（如远程服务器或移动网络），你可能需要设置得稍长一些。
     */
    private static RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(60000).setConnectTimeout(10000).build();

    /**
     * 是否开启同步政务系统申请材料
     * @return
     */
    private boolean verifyEnableSyncSqcl(){
        return apiConstant.verifyEnableSyncSqcl;
    }

    /**
     * 获取Token
     * @return
     */
    public String getToken(){
        String token = null;
//        String url = apiConstant.token_API+"?grant_type=client_credentials&client_id=&client_secret=";
        StringBuffer urlString = new StringBuffer(apiConstant.token_API);
        urlString.append("?").append("grant_type").append("=").append(apiConstant.token_grant_type);
        urlString.append("&").append("client_id").append("=").append(apiConstant.token_client_id);
        urlString.append("&").append("client_secret").append("=").append(apiConstant.token_client_secret);
        log.info("请求路径：{}",urlString.toString());
        HttpPost httpRequest = initHttpPost(urlString.toString());

        // 设置超时
        httpRequest.setConfig(requestConfig);

//        HttpGet httpRequest = new HttpGet(url);
        try {
//            httpRequest.setEntity(new StringEntity(urlString.toString(),"UTF-8"));
           /* StringEntity param = new StringEntity(urlString.toString());
            param.setContentType("application/x-www-form-urlencoded");
            httpRequest.setEntity(param);*/
            HttpResponse response = HttpClients.createDefault().execute(httpRequest);
            log.info("respone: {}",response.getStatusLine().getStatusCode());
            if (response.getStatusLine().getStatusCode() == 200){
                HttpEntity res = response.getEntity();
                if (res != null){
                    String result = EntityUtils.toString(res,"UTF-8");
                    JSONObject jsData = JSONObject.parseObject(result);
                    log.info("---------获取token-------------");
//                    log.info("{}",jsData);
                    if (StringUtils.isNotBlank(jsData.getString("access_token"))) {
                        token = jsData.getString("access_token");
                        log.info("access_token: {}", "成功");
                    }else {
                        log.error("token获取失败,参数为空!");
                    }
                }
            }
        }catch (Exception e){
            log.error("获取token失败，{}",e.getMessage());
        }
        return token;
    }

    /**
     * 验证token-令牌校验
     * @return
     */
    public String getTokenInfo(String sessionToken){
        String username = null;
        String errorMsg = "";
        StringBuffer urlString = new StringBuffer(apiConstant.tokenInfo);
        urlString.append("?").append("session_token").append("=").append(sessionToken);
        log.info("请求路径：{}",urlString.toString());
        HttpPost httpRequest = initHttpPost(urlString.toString());

        // 设置超时
        httpRequest.setConfig(requestConfig);

        try {
            HttpResponse response = HttpClients.createDefault().execute(httpRequest);

            if (response.getStatusLine().getStatusCode() == 200){
                HttpEntity res = response.getEntity();
                if (res != null){
                    String result = EntityUtils.toString(res,"UTF-8");
                    JSONObject jsData = JSONObject.parseObject(result);

                    log.info("---------验证token-令牌校验-------------");
//                    log.info("{}",jsData);
                    String code = jsData.getString("code");
                    log.info("code-{}",code);

                    if (code.equals("200")) {
                        log.info("message：{}",jsData.getString("message"));
                        JSONObject result1 = jsData.getJSONObject("result");
                        log.info("result-{}", result1);
                        username = result1.getString("username");
                        log.info("username-{}", username);
                    }else {
                        log.error("message：{}",jsData.getString("message"));
                        errorMsg = jsData.getString("message");
                    }
                }
            }
        }catch (Exception e){
            log.error("获取token失败，{}",e.getMessage());
            throw new BusinessException(e.getMessage());
        }

        if (StringUtils.isNotBlank(errorMsg)){
            throw new BusinessException(errorMsg);
        }
        return username;
    }

    /**
     * 获取接口提取时间戳，如果没有自动新建
     * @return
     */
    public SpcyRsJlxcrwsj getTimeStamp(){
        SpcyRsJlxcrwsj timeStamp = jlxcrwsjService.getById(SpcyConstant.XZSP_TIME_STAMP_ID);
        if(timeStamp==null){
            timeStamp = new SpcyRsJlxcrwsj();
            timeStamp.setId(SpcyConstant.XZSP_TIME_STAMP_ID);
            jlxcrwsjService.save(timeStamp);
        }
        return timeStamp;
    }

    /**
     * 初始化HttpPost请求头
     * @param url 请求地址
     * @return
     */
    private HttpPost initHttpPost(String url ){
        HttpPost httpRequest = new HttpPost(url);
        // 设置请求头，在Post请求中限制了浏览器后才能访问
//        httpRequest.addHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36");
//        httpRequest.addHeader("Accept", "*/*");
//        httpRequest.addHeader("Accept-Encoding", "gzip, deflate, br");
        httpRequest.addHeader("Content-Type", "application/json");
//        httpRequest.addHeader("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8");
//        httpRequest.addHeader("Connection", "keep-alive");
//        httpRequest.addHeader("X-Access-Token","eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NzAzMzUyODcsInVzZXJuYW1lIjoiYWRtaW4ifQ.jeo2rCx6XWP-9R5bQytsvLhhh-Ib5B5ONovC0s8xLLI");
        return httpRequest;
    }

    /**
     * 提取现场检查任务（含附件）
     * @param time_stamp 时间戳（不传提取所有，传值会取）
     * @param ywflcode 业务分类
     * @param user 办理人
     */
    public void tqSqsx(String time_stamp, String ywflcode, CurrentUserVo user, SpcyScheduleJobBasic jobBasic, String sqdbh) {
        boolean isLog = false;
        if (jobBasic == null){
            isLog = true;
        }
        StringBuffer zxLog = new StringBuffer("0");
        StringBuffer errorLog = new StringBuffer("0");

        String tokenString = getToken();//正式使用以后用这个
        String url = apiConstant.hqxcjcrw_API;
        HttpPost httpRequest = initHttpPost(url);

        // 设置超时
        httpRequest.setConfig(requestConfig);

        log.info("获取数据日期：{}",time_stamp);
        // 构建json参数
//        String tokenString = "463dba59f993f33ab7478afb5a220af7";//测试环境下使用

        String token = "\""+tokenString+"\"";
        String jsParam = "{" +
                "\"access_token\": "+token+"," +
                "\"param\":{" +
                "\"TIME_STAMP\": \""+time_stamp+"\"}" +
                "}";
        JSONObject json = JSONObject.parseObject(jsParam);
        httpRequest.setEntity(new StringEntity(json.toString(),"UTF-8"));
        try {
            HttpResponse response = HttpClients.createDefault().execute(httpRequest);

            if (response.getStatusLine().getStatusCode() == 200){

                HttpEntity res = response.getEntity();
                if (res != null) {
                    String s = EntityUtils.toString(res, "UTF-8");

                    JSONObject jsonObject2 = JSONObject.parseObject(s);

                    JSONObject status = jsonObject2.getJSONObject("STATUS");
                    String code = status.getString("CODE");
                    log.info("接口返回状态-》code: {}",code);

                    JSONObject data = jsonObject2.getJSONObject("data");

                    String lasttimestamp = data.getString("LASTTIMESTAMP");
                    log.info("接口日期：{}",lasttimestamp);

                    // 定时任务-才更新该日期状态
                    if (StringUtils.isNotBlank(ywflcode)) {
                        log.info("手动-获取行政审批数据-科室：{}",ywflcode);

                    }else {
                        log.info("定时任务-获取行政审批数据");

                        //请求成功以后更新时间戳
                        SpcyRsJlxcrwsj timeStamp = getTimeStamp();
//                    timeStamp.setFsjc(DateConversionUtils.DateToDays(new Date()));
                        timeStamp.setFsjc(lasttimestamp);
                        jlxcrwsjService.updateById(timeStamp);
                    }

                    String totaldata = data.getString("TOTALDATA");
                    log.info("获取数据条数-》totaldata: {}",totaldata);

                    List<XzspJkApiSqsxVo> list = JSONObject.parseArray(data.get("LIST").toString(), XzspJkApiSqsxVo.class);

                    if (list.size()>0) {

                        int count = 1;
                        for (XzspJkApiSqsxVo demo : list) {

                            /** 指定提取事项 */
                            if (StringUtils.isNotBlank(sqdbh)
                                    && StringUtils.isNotBlank(demo.getSqdbh())
                                    && !sqdbh.equals(demo.getSqdbh())){
                                continue;
                            }
                            log.info("序号：{}",count);
                            log.info("数据id: {}",demo.getId());
                            log.info("事项申请id：{}",demo.getSxsqjbxx_id());
                            log.info("企业统一社会信用代码：{}",demo.getTyshxydm());
                            log.info("企业名称：{}",demo.getQymc());
                            log.info("业务分类编码：{}",demo.getYwfl());
                            log.info("事项名称：{}",demo.getSxmc());

                            if (StringUtils.isBlank(demo.getId())){
                                errorLog.append("企业统一社会信用代码").append(demo.getTyshxydm()).append("\n");
                                errorLog.append("企业名称").append(demo.getQymc()).append("\n");
                                errorLog.append("业务分类编码").append(demo.getYwfl()).append("\n");
                                errorLog.append("事项名称").append(demo.getSxmc()).append("\n");
                                errorLog.append("数据id为空");
                            }

                            if (StringUtils.isBlank(demo.getSxsqjbxx_id())){
                                errorLog.append("企业统一社会信用代码").append(demo.getTyshxydm()).append("\n");
                                errorLog.append("企业名称").append(demo.getQymc()).append("\n");
                                errorLog.append("业务分类编码").append(demo.getYwfl()).append("\n");
                                errorLog.append("事项名称").append(demo.getSxmc()).append("\n");
                                errorLog.append("事项申请id为空");
                            }

                            // 检验是否存在该现场检查记录
                            SpcySqsxBasic sqsxBaisc = spcySqsxBaiscService.selectSqsxById(demo.getId());
                            if (sqsxBaisc != null){
                                // 中心已经退回，政务再次提交过来，重新生成待办
                                spcyFlowService.existsReturnZwxtSqsx(demo.getId());
                                continue;
                            }

                            // 转换对应的业务分类编码
                            if (StringUtils.isNotBlank(ywflcode)){
                                ywflcode = SpcyConstant.getXzspYwflBySpcyYwflcode(ywflcode);
                            }

                            // 如果不存在
                            if (StringUtils.isNotBlank(demo.getYwfl()) && sqsxBaisc == null
                                    && (StringUtils.isBlank(ywflcode) || Objects.equals(ywflcode,demo.getYwfl()))
                            ){
                                SpcySqsxBasic newBaisc = new SpcySqsxBasic();
                                String sqsxid = demo.getId();
                                newBaisc.setId(sqsxid);
                                newBaisc.setFsxsqjbxxid(demo.getSxsqjbxx_id());
                                newBaisc.setFsxmc(demo.getSxmc());

                                // 转换业务分类编码
                                String spcyYwflcode = SpcyConstant.getSpcyYwflcodeByXzspYwfl(demo.getYwfl());
                                newBaisc.setFywflcode(spcyYwflcode);

                                // 审查模式
                                if (spcyYwflcode.equals(SpcyConstant.YWFL_CODE_YLQX)){
                                    // 医疗器械 模式
                                    newBaisc.setFscms(SpcyConstant.SQSX_SCMS_SCJCANBJSSC);
                                    newBaisc.setFsplx(SpcyConstant.Sp_type_Ns);
                                }
                                else if (spcyYwflcode.equals(SpcyConstant.YWFL_CODE_YPZC)){
                                    // 药品注册 模式
                                    newBaisc.setFscms(SpcyConstant.SQSX_SCMS_SCJCANBJSSC);
                                    newBaisc.setFsplx(SpcyConstant.Sp_type_Ns);
                                }
                                else if (spcyYwflcode.equals(SpcyConstant.YWFL_CODE_HZP)){
                                    // 化妆品模式
                                    newBaisc.setFscms(SpcyConstant.SQSX_SCMS_SCJCANBJSSC);
                                    newBaisc.setFsplx(SpcyConstant.Sp_type_Ns);
                                }
                                else if (spcyYwflcode.equals(SpcyConstant.YWFL_CODE_YPSC)){
                                    // 药品生产 模式
                                    newBaisc.setFscms(SpcyConstant.SQSX_SCMS_XCJC);
                                }
                                else if (spcyYwflcode.equals(SpcyConstant.YWFL_CODE_YPJY)){
                                    // 药品流通 模式
                                    newBaisc.setFscms(SpcyConstant.SQSX_SCMS_XCJC);
                                }

                                newBaisc.setFywflname(SpcyConstant.getYwclNameByCode(spcyYwflcode));
                                newBaisc.setFsqsj(demo.getSqsj());
                                newBaisc.setFqymc(demo.getQymc());
                                newBaisc.setFtyshxydm(demo.getTyshxydm());
                                newBaisc.setFqyfddbrfzr(demo.getQyfddbrfzr());
                                newBaisc.setFqylxr(demo.getQylxr());
                                newBaisc.setFqylxrdh(demo.getQylxrdh());
                                newBaisc.setFqyzszcdz(demo.getQyzszcdz());
                                newBaisc.setFcpmc(demo.getCpmc());
                                newBaisc.setFszdq(demo.getSzdq());
                                newBaisc.setFxxdz(demo.getXxdz());
                                newBaisc.setFsqdbh(demo.getSqdbh());
                                newBaisc.setFspdwmc(demo.getSpdwmc());
                                newBaisc.setFbldwmc(demo.getBldwmc());
                                newBaisc.setFbldwid(demo.getBldw_id());
                                newBaisc.setFblr(demo.getBlr());
                                newBaisc.setFblrid(demo.getBlr_id());
                                newBaisc.setFfsr(demo.getFsr());
                                newBaisc.setFfssj(demo.getFssj());

                                if (newBaisc.getFfssj() == null){
                                    newBaisc.setFfssj(new Date());
                                }
                                newBaisc.setFslsj(new Date());

                                // 根据当前企业社会信用代码查询，是否存在
                                List<SpcyQyJbxx> qy = spcyQyJbxxService.list(new LambdaQueryWrapper<SpcyQyJbxx>()
                                    .eq(SpcyQyJbxx::getFtyshxydm, demo.getTyshxydm()));
                                if (CollectionUtils.isEmpty(qy)){
                                    // 新增企业基本信息
                                    SpcyQyJbxx qyJbxx = new SpcyQyJbxx();
                                    String qyId = GetUuIdUtils.NotReplaceUuId();
                                    qyJbxx.setId(qyId);
                                    qyJbxx.setFqymc(demo.getQymc());
                                    qyJbxx.setFtyshxydm(demo.getTyshxydm());
                                    qyJbxx.setFqyfddbrfzr(demo.getQyfddbrfzr());
                                    qyJbxx.setFqylxr(demo.getQylxr());
                                    qyJbxx.setFqylxrdh(demo.getQylxrdh());
                                    qyJbxx.setFqyzszcdz(demo.getQyzszcdz());
                                    qyJbxx.setFszdq(demo.getSzdq());
                                    qyJbxx.setFxxdz(demo.getXxdz());
                                    spcyQyJbxxService.save(qyJbxx);

                                    // 新增企业产品
                                    /*SpcyQyCpxx cpxx = new SpcyQyCpxx();
                                    cpxx.setFcpmc(qyId);
                                    cpxx.setFcpmc(demo.getCpmc());
                                    spcyQyCpxxService.addQycpxx(cpxx);*/

                                    String qyLog = "行政审评-提取现场检查数据-新增企业: ";
                                    Map<String, Object> qyMap = ObjectToMapUtils.objectToMap(qyJbxx);
                                    qyLog += LogUtils.MapToStringMethod(qyMap);
                                    spcyLogService.addLogs(LogConstant.LOGS_QY_JBXX,qyLog,sqsxid,LogConstant.LOGS_QY_JBXX,SpcyConstant.LOGS_SYS_TYPE_XZ);

                                    newBaisc.setFqyid(qyId);
                                }else {
                                    newBaisc.setFqyid(qy.get(0).getId());

                                    // 新增企业产品
                                    /*SpcyQyCpxx cpxx = new SpcyQyCpxx();
                                    cpxx.setFqyid(qy.get(0).getId());
                                    cpxx.setFcpmc(demo.getCpmc());
                                    spcyQyCpxxService.addQycpxx(cpxx);*/
                                }

                                newBaisc.setFxzspzt(SpcyConstant.SQSX_BASIC_XZSPZT_YES); // 行政审批数据
                                newBaisc.setFsyts("0");
                                spcySqsxBaiscService.save(newBaisc);
//                                FlowConstant flowConstant = SpcyConstant.getFlowConstant(demo.getYwfl());
//                                flowService.initJob(flowConstant,newBaisc.getId(),user);

                                /** 初始化流程 */
                                Result result = spcyFlowService.initYwflJob(spcyYwflcode, newBaisc.getId(), user, false);
                                if (!result.isSuccess()){
                                    errorLog.append("初始化，流程任务失败").append(": ").append(result.getMessage());
                                    log.error("初始化，流程任务失败-{}",result.getMessage());
                                }

                                if (spcyYwflcode.equals(SpcyConstant.YWFL_CODE_YPSC)){
                                    // 药品生产
                                    /*Result result = ypscFlowService.initJob(newBaisc.getId(), user);
                                    if (!result.isSuccess()){
                                        errorLog.append("初始化，流程任务失败").append(": ").append(result.getMessage());
                                        log.error("初始化，流程任务失败-{}",result.getMessage());
                                    }*/

                                    /*Result result = spcyFlowService.initYwflJob(spcyYwflcode, newBaisc.getId(), user, false);
                                    if (!result.isSuccess()){
                                        errorLog.append("初始化，流程任务失败").append(": ").append(result.getMessage());
                                        log.error("初始化，流程任务失败-{}",result.getMessage());
                                    }*/
                                }else {
                                    errorLog.append("\n").append("事项id：").append(demo.getId());
                                    errorLog.append("\n").append("事项名称: ").append(demo.getSxmc());
                                    errorLog.append("\n").append("不处理该业务分类").append(": ").append(demo.getYwfl());
                                    log.error("不处理该业务分类: {}",demo.getYwfl());
                                }
                                /*else if (spcyYwflcode.equals(SpcyConstant.YWFL_CODE_YPZC)){
                                    // 药品注册
                                    Result result = ypzcFlowService.initJob(newBaisc.getId(), user);
                                    if (!result.isSuccess()){
                                        errorLog.append("初始化，流程任务失败").append(": ").append(result.getMessage());
                                        log.error("初始化，流程任务失败-{}",result.getMessage());
                                    }
                                }
                                else if (spcyYwflcode.equals(SpcyConstant.YWFL_CODE_YPJY)){
                                    // 药品流通
                                    Result result = ypltFlowService.initJob(newBaisc.getId(), user);
                                    if (!result.isSuccess()){
                                        errorLog.append("初始化，流程任务失败").append(": ").append(result.getMessage());
                                        log.error("初始化，流程任务失败-{}",result.getMessage());
                                    }
                                }
                                else if (spcyYwflcode.equals(SpcyConstant.YWFL_CODE_YLQX)){
                                    // 医疗器械
                                    Result result = ylqxFlowService.initJob(newBaisc.getId(), user);
                                    if (!result.isSuccess()){
                                        errorLog.append("初始化，流程任务失败").append(": ").append(result.getMessage());
                                        log.error("初始化，流程任务失败-{}",result.getMessage());
                                    }
                                }
                                else if (spcyYwflcode.equals(SpcyConstant.YWFL_CODE_HZP)){
                                    // 化妆品
                                    Result result = hzpFlowService.initJob(newBaisc.getId(), user);
                                    if (!result.isSuccess()){
                                        errorLog.append("初始化，流程任务失败").append(": ").append(result.getMessage());
                                        log.error("初始化，流程任务失败-{}",result.getMessage());
                                    }
                                }else {
                                    errorLog.append("\n").append("事项id：").append(demo.getId());
                                    errorLog.append("\n").append("事项名称: ").append(demo.getSxmc());
                                    errorLog.append("\n").append("不存在该业务分类").append(": ").append(demo.getYwfl());
                                    log.error("不存在该业务分类: {}",demo.getYwfl());
                                }*/

                                //需补齐：日志
                                String sqsxLog = "行政审评数据对接-新增获取申请事项：";
                                Map<String, Object> sqsxMap = ObjectToMapUtils.objectToMap(newBaisc);
                                sqsxLog += LogUtils.MapToStringMethod(sqsxMap);
                                spcyLogService.addLogs(LogConstant.LOGS_SQSX_BASIC,sqsxLog,sqsxid,LogConstant.LOGS_SQSX_BASIC,SpcyConstant.LOGS_SYS_TYPE_XZ);

                                StringBuffer sqsxLogBuf = new StringBuffer("行政审评数据对接-新增获取申请事项：");
                                sqsxLogBuf.append("序号：[").append(count).append("]\n");
                                sqsxLogBuf.append("数据id：[").append(demo.getId()).append("]\n");
                                sqsxLogBuf.append("事项申请id：[").append(demo.getSxsqjbxx_id()).append("]\n");
                                sqsxLogBuf.append("申请单编号：[").append(demo.getSqdbh()).append("]\n");
                                sqsxLogBuf.append("企业统一社会信用代码：[").append(demo.getTyshxydm()).append("]\n");
                                sqsxLogBuf.append("企业名称：[").append(demo.getQymc()).append("]\n");
                                sqsxLogBuf.append("企业法定代表人/负责人：[").append(demo.getQyfddbrfzr()).append("]\n");
                                sqsxLogBuf.append("企业联系人：[").append(demo.getQylxr()).append("]\n");
                                sqsxLogBuf.append("企业联系人电话：[").append(demo.getQylxrdh()).append("]\n");
                                sqsxLogBuf.append("企业住所/注册地址：[").append(demo.getQyzszcdz()).append("]\n");
                                sqsxLogBuf.append("所在地区：[").append(demo.getSzdq()).append("]\n");
                                sqsxLogBuf.append("详细地址：[").append(demo.getXxdz()).append("]\n");
                                sqsxLogBuf.append("业务分类编码：[").append(demo.getYwfl()).append("]\n");
                                sqsxLogBuf.append("事项名称：[").append(demo.getSxmc()).append("]\n");
                                sqsxLogBuf.append("发送人：[").append(demo.getFsr()).append("]\n");
                                if (demo.getFssj() != null) {
                                    sqsxLogBuf.append("发送时间：[").append(DateConversionUtils.DateToDays(demo.getFssj())).append("]\n");
                                }else {
                                    sqsxLogBuf.append("发送时间：[").append("为空").append("]\n");
                                }
                                if (demo.getSqsj() != null){
                                    sqsxLogBuf.append("申请时间：[").append(DateConversionUtils.DateToDays(demo.getSqsj())).append("]\n");
                                }else {
                                    sqsxLogBuf.append("发送时间：[").append("为空").append("]\n");
                                }


                                // 定时任务执行日志内容
                                if (jobBasic != null) {
                                    SpcyScheduleJobLog jobLog = new SpcyScheduleJobLog();
                                    jobLog.setId(GetUuIdUtils.ReplaceUuId());
                                    jobLog.setFpid(sqsxid);
                                    jobLog.setFzxrwid(jobBasic.getId());
                                    jobLog.setFzxnr(sqsxLogBuf.toString());
                                    spcyScheduleJobLogService.save(jobLog);
                                }else {
                                    zxLog.append(sqsxLog).append("\n");
                                }

                                /** 提取文件材料 */
//                                if (verifyEnableSyncSqcl()) {
                                if (true){
                                    sqsxQywjclService.syncZwxtQysqclAndMlApi(demo.getSbclxxL(), sqsxid, demo.getSxsqjbxx_id());
                                }
                                // 获取事项文件 2023-8-17 10:00 注销
                                /*
                                List<XzspJkApiSbclxxlVo> sbclxxLList = demo.getSbclxxL();
                                if (CollectionUtils.isNotEmpty(sbclxxLList)) {
                                    for (XzspJkApiSbclxxlVo sbclxxL : sbclxxLList) {
                                        SpcySqsxWjjl wjjl = spcySqsxWjjlService.getById(sbclxxL.getId());
                                        if (wjjl == null) {
                                            SpcySqsxWjjl newWjjl = new SpcySqsxWjjl();
                                            if (StringUtils.isNotBlank(sbclxxL.getId())) {
                                                newWjjl.setId(sbclxxL.getId());
                                            }
                                            if (StringUtils.isNotBlank(sbclxxL.getSxsqjbxx_id())){
                                                newWjjl.setFpid(demo.getId());
                                            }
                                            newWjjl.setFwjlx1(SpcyConstant.getXzspWjlxName(sbclxxL.getCllb()));

                                            if (StringUtils.isNotBlank(sbclxxL.getClmc())){
                                                newWjjl.setFwjlx2(sbclxxL.getClmc());
                                            }
                                            newWjjl.setFywflcode(demo.getYwfl());
                                            if (StringUtils.isNotBlank(sbclxxL.getFjmc())){
                                                newWjjl.setFwjxsmc(sbclxxL.getFjmc());
                                            }
                                            spcySqsxWjjlService.save(newWjjl);
                                            //保存具体文件
                                            this.tqSbcl(sbclxxL.getId());
                                        }
                                    }
                                }
                                */
                            }else {
                                if (sqsxBaisc != null){
                                    log.info("该申请事项已经提取了！");
                                }

                                if (StringUtils.isBlank(demo.getYwfl())) {
                                    log.info("业务分类编码为空!!!!!!!!");
                                    log.info("错误-序号：{}", count);
                                    log.info("错误-数据id: {}", demo.getId());
                                    log.info("错误-事项申请id：{}", demo.getSxsqjbxx_id());
                                    log.info("错误-企业统一社会信用代码：{}", demo.getTyshxydm());
                                    log.info("错误-企业名称：{}", demo.getQymc());
                                    log.info("错误-事项名称：{}", demo.getSxmc());
                                    log.info("错误-业务分类编码：{}", demo.getYwfl());
                                }
                            }

                            count++;
                        }
                    }
                }

            }
        }catch (Exception e){
            errorLog.append("\n").append("获取行政审批数据出错【Exception】").append(e.getMessage());
            log.error("获取行政审批数据出错【Exception】-{}",e.getMessage());
        }


        if (jobBasic == null){
            SpcyScheduleJobBasic logJobBasic = new SpcyScheduleJobBasic();
            logJobBasic.setId(GetUuIdUtils.ReplaceUuId());
            logJobBasic.setFmethod(ScheduleConstant.rw_name_getXzspData_Method);
            logJobBasic.setFrwmc("手动执行："+ScheduleConstant.rw_name_getXzspData); // 任务名称
            logJobBasic.setFzxsj(DateConversionUtils.DateToDays(new Date()));
            logJobBasic.setFycqk(errorLog.toString());
            logJobBasic.setFzxqk(zxLog.toString());
            if (!errorLog.toString().equals("0")){
                logJobBasic.setFzxzt(ScheduleConstant.Job_Basic_Error);
            }else {
                logJobBasic.setFzxzt(ScheduleConstant.Job_Basic_Success);
            }
            logJobBasic.setFjssj(new Date());
            spcyScheduleJobBasicService.save(logJobBasic);
        }

        // 定时任务-记录
        if (jobBasic != null && !errorLog.toString().equals("0")) {
            jobBasic.setFzxzt(ScheduleConstant.Job_Basic_Error);
            jobBasic.setFycqk(errorLog.toString());
            jobBasic.setFjssj(new Date());
            spcyScheduleJobBasicService.updateById(jobBasic);
        }
    }

    /**
     * 提取业务部门经办人
     * @param sqsxjbid 申请事项基本id
     */
    public List<BusinessDept> tqYwbmjbr(String sqsxjbid){
        List<BusinessDept> resultDept = new ArrayList<>();

        String url = apiConstant.ywbmjbrlb_API;
        HttpPost httpRequest = initHttpPost(url);

        // 设置超时
        httpRequest.setConfig(requestConfig);

        // json参数
//        String tokenString = "463dba59f993f33ab7478afb5a220af7";//测试环境下使用
        String tokenString = getToken();//正式使用以后用这个
        String token = "\""+tokenString+"\"";
        String jsParam = "{" +
                "\"access_token\": "+token+"," +
                "\"param\":{" +
                "\"id\": \""+sqsxjbid+"\"}" +
                "}";
        JSONObject json = JSONObject.parseObject(jsParam);
        httpRequest.setEntity(new StringEntity(json.toString(),"UTF-8"));
        try {
            HttpResponse response = HttpClients.createDefault().execute(httpRequest);

            if (response.getStatusLine().getStatusCode() == 200){
                HttpEntity res = response.getEntity();
                if (res != null) {
                    String s = EntityUtils.toString(res, "UTF-8");

                    log.info("---------获取业务部门经办人列表-------------");

                    JSONObject jsonObject2 = JSONObject.parseObject(s);
                    log.info("jsonObject2--------------");
                    log.info(jsonObject2.toJSONString());

                    JSONObject status = jsonObject2.getJSONObject("STATUS");
//                    log.info("status-----");
//                    log.info(status.toString());

                    String code = status.getString("CODE");
//                    log.info("code------: {}", code);

                    if (Objects.equals(code,"00")) {
                        List<BusinessDept> data = JSONObject.parseArray(jsonObject2.get("data").toString(), BusinessDept.class);
                        log.info("data--------");
                        log.info(data.toString());

                        resultDept.addAll(data);
//                        System.out.println("resultDept--------");
//                        System.out.println(resultDept);

                        /*for (BusinessDept businessDept : data) {
                            System.out.println(businessDept);
                        }*/
                    }
                }
            }
        }catch (Exception e){
            log.error("提取业务部门经办人-错误-{}",e.getMessage());
        }

        return resultDept;
    }

    /**
     * 保存申请事项-选择的移送人id
     */
    public void updateSqsxYwbmjbr(String sqsxid, String ysrid){
        if (StringUtils.isBlank(sqsxid)){
            return;
        }

        List<BusinessDept> businessDepts = this.tqYwbmjbr(sqsxid);
        if (CollectionUtils.isNotEmpty(businessDepts)){
            for (BusinessDept dept : businessDepts){
                if (dept.getId().equals(ysrid)){
                    spcySqsxBaiscService.updateSqsxYwbmjbr(sqsxid, dept);
                    /*sqsx.setFxzspysrid(ysrid);
                    sqsx.setFxzspysrmc(dept.getName());
                    sqsx.setFxzspysrbmid(dept.getDeptId());
                    sqsx.setFxzspysrbm(dept.getDeptName());
                    spcySqsxBaiscService.updateById(sqsx);*/
                }
            }
        }

    }

    /**
     * 提取上报材料
     * @param fjid 行政审批接口给过来的附件id
     */
    public void tqSbcl(String fjid) {
        this.tqSbcl(fjid, null, null);
    }
    /** 提取上报材料 */
    public void tqSbcl(String fjid, SpcySqsxQywjcl qywjcl, String wjHz) {
        // 创建HttpGet对象
        String url= apiConstant.hqsbclfj_API+"?fjid="+fjid;

        HttpGet httpRequst = new HttpGet(url);
        httpRequst.addHeader("Content-type", "application/json; charset=utf-8");
        httpRequst.addHeader("Accept", "application/json");
        try {
            HttpResponse httpResponse = HttpClients.createDefault().execute(httpRequst);
            if (httpResponse.getStatusLine().getStatusCode() == 200) {
                HttpEntity httpEntity = httpResponse.getEntity();
                String fileType=httpEntity.getContentType().getValue();
                //文件流
                InputStream result = httpEntity.getContent();
                Header contentHeader = httpResponse.getFirstHeader("Content-Disposition");
                String filename = null;
                if (contentHeader != null) {
                    HeaderElement[] values = contentHeader.getElements();
                    if (values.length == 1) {
                        HeaderElement value =values[0];
                        NameValuePair param = value.getParameterByName("filename");
                        if (param != null) {
                            filename = new String(param.getValue().toString().getBytes("ISO-8859-1"), "UTF-8");
                        }
                    }
                }

                // 新增
                if (StringUtils.isBlank(wjHz)) {
                    wjHz = filename.substring(filename.lastIndexOf("."));
                    filename = GetUuIdUtils.NotReplaceUuId() + wjHz;
                }else {
                    filename = GetUuIdUtils.ReplaceUuId() + wjHz;
                }

                //将文件 保存到本地
                int index;
                byte[] bytes = new byte[1024];

                String newDir = "/" + DateConversionUtils.DateToMonthTwo(new Date());

                String dirUrl = localFileUploadUtils.getTempFileRootUrl() + newDir;
                File newDirUrl = new File(dirUrl);
                if (!newDirUrl.exists()){
                    newDirUrl.mkdirs();
                }

                FileOutputStream downFile = new FileOutputStream(dirUrl + "/" + filename);
                while ((index = result.read(bytes)) != -1) {
                    downFile.write(bytes, 0, index);
                    downFile.flush();
                }
                downFile.close();
                result.close();

                String absPath = dirUrl + "/" + filename;
                /** pdf 加水印 */
                if (StringUtils.isNotBlank(wjHz) && wjHz.equals(".pdf")) {
                    String destPdfUrl = localFileUploadUtils.getTempFileRootUrl() + "/";
                    destPdfUrl += GetUuIdUtils.ReplaceUuId() + wjHz;

                    FileOutputStream downloadFile = null;
                    try {
                        downloadFile = new FileOutputStream(destPdfUrl);
                    } catch (FileNotFoundException e) {
                        log.error("[FileNotFoundException]-{}",e.getMessage());
                    }

                    boolean flag = false;
                    try {
                        PdfUtils.setWordMark(downloadFile, absPath, BusinessConstant.FILE_SY_NAME, true);
                        flag = true;
                    } catch (DocumentException e) {
                        log.error("给pdf文件加水印出错-【DocumentException】：{}",e.getMessage());
                    } catch (IOException e) {
                        log.error("给pdf文件加水印出错-【IOException】：{}",e.getMessage());
                    }

                    if (flag) {
                        spcyMinioUtils.putFile(qywjcl.getFcllj(), new File(destPdfUrl), ".pdf");
                    }else {
                        spcyMinioUtils.putFile(qywjcl.getFcllj(), new File(absPath), ".pdf");
                    }

                }else {

                    spcyMinioUtils.putFile(qywjcl.getFcllj(), new File(absPath), wjHz);
                }

            }
        }
        catch (Exception e) {
            log.error("提取政务服务-上报材料-接口错误: {}", e.getMessage());
            e.printStackTrace();
        }
    }

    /**
     * 推送任务受理信息
     * @param xzspJkApiSlxxVo
     */
    public void tsSlxx(XzspJkApiSlxxVo xzspJkApiSlxxVo, SpcyScheduleJobBasic scheduleJob){
        if (scheduleJob == null){
            scheduleJob = new SpcyScheduleJobBasic();
            scheduleJob.setId(GetUuIdUtils.ReplaceUuId());
            scheduleJob.setFmethod(ScheduleConstant.Xzsp_Data_Scjl_Method);
            scheduleJob.setFrwmc(ScheduleConstant.Xzsp_Data_Scjl_Name); // 任务名称
            scheduleJob.setFzxsj(DateConversionUtils.DateToDays(new Date()));
            scheduleJob.setFjssj(new Date());
        }
        StringBuffer msg = new StringBuffer("0");

        String tokenString = getToken();//正式使用以后用这个
        String url = apiConstant.tsxcjcrwslxx_API;
        HttpPost httpRequest = initHttpPost(url);

        // 设置超时
        httpRequest.setConfig(requestConfig);

        // json参数
        String sxsqjbxx_id = xzspJkApiSlxxVo.getSxsqjbxx_id();
        String slbyslr = xzspJkApiSlxxVo.getSlbyslr();
        Date slbyslsj1 = xzspJkApiSlxxVo.getSlbyslsj();
        String slbyslsj = "";
        if (slbyslsj1 != null) {
            slbyslsj = DateConversionUtils.DateToDays(slbyslsj1);
        }
        String slbyslyj = xzspJkApiSlxxVo.getSlbyslyj();
        String sczt = xzspJkApiSlxxVo.getSczt();

        String token = "\""+tokenString+"\"";
        String jsParam = "{" +
                "\"access_token\": "+token+"," +
                "\"param\":{" +
                "\"sxsqjbxx_id\":\""+sxsqjbxx_id+"\"," +
                "\"slbyslr\":\""+slbyslr+"\"," +
                "\"slbyslsj\":\""+slbyslsj+"\"," +
                "\"slbyslyj\":\""+slbyslyj+"\"," +
                "\"sczt\":\""+sczt+"\"" +
                "}}";
        JSONObject json = JSONObject.parseObject(jsParam);
        httpRequest.setEntity(new StringEntity(json.toString(),"UTF-8"));
        try {
            msg.append("接口调用：").append(json.toString()).append("\n");
            HttpResponse response = HttpClients.createDefault().execute(httpRequest);

            if (response.getStatusLine().getStatusCode() == 200){
                HttpEntity res = response.getEntity();
                if (res != null) {
                    String s = EntityUtils.toString(res, "UTF-8");
                    JSONObject jsonObject2 = JSONObject.parseObject(s);
                    JSONObject status = jsonObject2.getJSONObject("STATUS");
                    String code = status.getString("CODE");

                    msg.append("返回值：").append(jsonObject2).append("\n");

                    if (Objects.equals(code,"00")) {
                        scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Success);
                        log.info("推送任务受理成功：{}",code);
                    }else {
                        log.info("推送任务受理失败：code:{}; msg: {}", code, status.getString("TEXT"));
                        msg.append(code).append("】推送任务受理失败：").append(status.getString("TEXT"));
                        scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
                    }

                }else {
                    scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
                }
            }else {
                msg.append("推送任务受理失败：").append("response.getStatusLine().getStatusCode()").append("不为200");
                msg.append("为：").append(response.getStatusLine().getStatusCode());
                scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
            }
        }catch (Exception e){
            scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
            msg.append("推送任务受理失败：").append(e.getMessage());
            log.error("推送任务受理失败：{}", e.getMessage());
        }

        scheduleJob.setFycqk(msg.toString());
        spcyScheduleJobBasicService.save(scheduleJob);
    }

    /**
     * 推送现场检查任务审查结论信息
     */
    public void tsSpcyjl(XzspJkApiSpcyjlVo xzspJkApiSpcyjlVo, SpcyScheduleJobBasic scheduleJob){
        if (scheduleJob == null){
            scheduleJob = new SpcyScheduleJobBasic();
            scheduleJob.setId(GetUuIdUtils.ReplaceUuId());
            scheduleJob.setFmethod(ScheduleConstant.Xzsp_Data_Scjl_Method);
            scheduleJob.setFrwmc(ScheduleConstant.Xzsp_Data_Scjl_Name); // 任务名称
            scheduleJob.setFzxsj(DateConversionUtils.DateToDays(new Date()));
            scheduleJob.setFjssj(new Date());
        }
        StringBuffer msg = new StringBuffer("0");

        String tokenString = getToken();//正式使用以后用这个
        String url = apiConstant.tsxcjcrwscjlxx_API;
        HttpPost httpRequest = initHttpPost(url);

        // 设置超时
        httpRequest.setConfig(requestConfig);

        // json参数
        String sxsqjbxx_id = xzspJkApiSpcyjlVo.getSxsqjbxx_id();
        String scjlydr = xzspJkApiSpcyjlVo.getScjlydr();
        String scjl = xzspJkApiSpcyjlVo.getScjl();
        String ywbmjbrid = xzspJkApiSpcyjlVo.getYwbmjbrid();

        String token = "\""+tokenString+"\"";
        String jsParam = "{" +
                "\"access_token\": "+token+"," +
                "\"param\":{" +
                "\"sxsqjbxx_id\":\""+sxsqjbxx_id+"\"," +
                "\"scjlydr\":\""+scjlydr+"\"," +
                "\"scjl\":\""+scjl+"\"," +
                "\"ywbmjbrid\":\""+ywbmjbrid+"\"" +
                "}}";
        JSONObject json = JSONObject.parseObject(jsParam);
        httpRequest.setEntity(new StringEntity(json.toString(),"UTF-8"));
        try {
            msg.append("接口调用：").append(json.toString()).append("\n");
            HttpResponse response = HttpClients.createDefault().execute(httpRequest);

            if (response.getStatusLine().getStatusCode() == 200){
                HttpEntity res = response.getEntity();
                if (res != null) {
                    String s = EntityUtils.toString(res, "UTF-8");
                    JSONObject jsonObject2 = JSONObject.parseObject(s);
                    JSONObject status = jsonObject2.getJSONObject("STATUS");
                    String code = status.getString("CODE");

//                    msg.append("接口调用：").append(json.toString()).append("\n");
                    msg.append("返回值：").append(jsonObject2).append("\n");

                    if (Objects.equals(code,"00")) {
                        scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Success);
                        log.info("推送审查结论成功：{}", code);

                    }else {

                        log.error("推送审查结论失败：code: {}; msg: {}", code, status.getString("TEXT"));
                        msg.append(code).append("】推送审查结论失败：");
                        msg.append(status.getString("TEXT"));
                        scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
                    }

                }else {
                    scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
                }
            }else {
                msg.append("推送审查结论失败：").append("response.getStatusLine().getStatusCode()").append("不为200");
                msg.append("为：").append(response.getStatusLine().getStatusCode());
                scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
            }
        }catch (Exception e){
            log.error("推送审查结论失败：{}",e.getMessage());
            scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
            msg.append("推送审查结论失败：").append(e.getMessage());
        }

        scheduleJob.setFycqk(msg.toString());
        spcyScheduleJobBasicService.save(scheduleJob);
    }

    /**
     * 推送现场检查材料
     */
    public HttpResult<?> tsJccl(File file, String fileName, String sxsqjbxxId, String fjcjr){

        fjcjr = Optional.ofNullable(fjcjr).orElseGet(()->"admin");

        StringBuffer msg = new StringBuffer("0");
        msg.append("\n").append("【文件名】：").append(fileName);

        String token = getToken();//正式使用以后用这个
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            log.error("推送现场检查材料，获取文件流出错，文件不存在: {}",e.getMessage());
            msg.append("【推送现场检查材料，获取文件流出错，文件不存在】: ").append(e.getMessage());
            return HttpResult.error(msg.toString());
        }

        if (StringUtils.isEmpty(sxsqjbxxId)){
            msg.append("【推送现场检查材料，获统错误，参数缺少【事项申请id】】;");
            return HttpResult.error(msg.toString());
        }

        String sxsqjbxx_id = sxsqjbxxId;
        String url = apiConstant.tsxcjccl_API;
//        String token = "463dba59f993f33ab7478afb5a220af7";
        HttpPost httpRequest = new HttpPost(url);

        // 设置超时
        httpRequest.setConfig(requestConfig);

        try {
            // json参数
//            MultipartFile file = siteMaterialsVo.getFile();
            MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
            multipartEntityBuilder.setMode(HttpMultipartMode.RFC6532);   // 处理中文文件名称乱码
            multipartEntityBuilder.setCharset(Charset.forName("UTF-8"));
            multipartEntityBuilder.addBinaryBody("file", fileInputStream, ContentType.MULTIPART_FORM_DATA, fileName);
            multipartEntityBuilder.addTextBody("sxsqjbxx_id", sxsqjbxx_id);
            multipartEntityBuilder.addTextBody("fjcjr", fjcjr);
            multipartEntityBuilder.addTextBody("access_token",token);
            HttpEntity httpEntity = multipartEntityBuilder.build();
            httpRequest.setEntity(httpEntity);

            HttpResponse response = HttpClients.createDefault().execute(httpRequest);
            if (response.getStatusLine().getStatusCode() == 200){
                HttpEntity res = response.getEntity();

//                log.info("推送材料");

                if (res != null) {
                    String s = EntityUtils.toString(res, "UTF-8");
                    JSONObject jsonObject = JSONObject.parseObject(s);
                    JSONObject status = jsonObject.getJSONObject("STATUS");
                    String code = status.getString("CODE");

                    msg.append("返回值：").append(jsonObject).append("\n");
                    /*log.info("推送材料返回码code: {}", code);
                    log.info("推送材料返回信息text: {}", status.getString("TEXT"));*/

                    /*msg.append("【推送材料返回码code】：").append(code);
                    msg.append("【推送材料返回信息text】：").append(status.getString("TEXT"));*/
                    if (Objects.equals(code,"00")){
//                        log.info("推送材料成功");
                        msg.append("【推送材料成功-状态】：").append(code);
                    }else {
                        log.error("推送材料返回码code: {}", code);
                        log.error("推送材料失败：{}",status.getString("TEXT"));
                        msg.append("【推送材料失败】: ").append(status.getString("TEXT"));
                        return HttpResult.error(msg.toString());
                    }
                }else {
                    msg.append("【推送材料失败：response.getEntity()为空。】");
                    return HttpResult.error(msg.toString());
                }
            }else {
                log.error("推送材料请求失败，状态码不是200");
                msg.append("【推送材料请求失败：状态码不是200;】");
                msg.append("接口状态：");
                msg.append(response.getStatusLine().getStatusCode());
                return HttpResult.error(msg.toString());
            }
        }catch (Exception e){
//            throw new SystemException(e.getMessage());
            log.error("异常错误-推送材料失败：{}",e.getMessage());
            msg.append("【异常错误-推送材料失败】：").append(e.getMessage());
            return HttpResult.error(msg.toString());
        }

        return HttpResult.ok(msg.toString());
    }


    /**
     * 退回政务服务接口
     * @param sxsqjbxx_id 事项申请基本信息id
     * @param thyy 退回原因
     * @param thblr 退回办理人
     * @param thsj 退回时间
     * @param username 退回账号
     */
//    @Async(value = "asyncMiddleTask")
    public boolean returnZwfwxt(String sxsqjbxx_id,String thyy,String thblr,String thsj,String username,SpcyScheduleJobBasic scheduleJob){
        boolean resultFlag = true;

        if (scheduleJob == null){
            scheduleJob = new SpcyScheduleJobBasic();
            scheduleJob.setId(GetUuIdUtils.ReplaceUuId());
            scheduleJob.setFmethod("returnZwfwxt");
            scheduleJob.setFrwmc("行政审批数据-退回政务服务接口"); // 任务名称
            scheduleJob.setFzxsj(DateConversionUtils.DateToDays(new Date()));
            scheduleJob.setFjssj(new Date());
        }

        StringBuffer msg = new StringBuffer("0");
        String errorLog = "";

        String tokenString = getToken();//正式使用以后用这个
        String url = apiConstant.thzwfw_API;
        HttpPost httpRequest = initHttpPost(url);

        // 设置超时
        httpRequest.setConfig(requestConfig);

        String token = "\""+tokenString+"\"";
        String jsParam = "{" +
                "\"access_token\": "+token+"," +
                "\"param\":{" +
                "\"sxsqjbxx_id\":\""+sxsqjbxx_id+"\"," +
                "\"thyy\":\""+thyy+"\"," +
                "\"thblr\":\""+thblr+"\"," +
                "\"thsj\":\""+thsj+"\"," +
                "\"username\":\""+username+"\"" +
                "}}";
        JSONObject json = JSONObject.parseObject(jsParam);
        httpRequest.setEntity(new StringEntity(json.toString(),"UTF-8"));
        try {
            msg.append("接口调用：").append(json.toString()).append("\n");
            HttpResponse response = HttpClients.createDefault().execute(httpRequest);

            if (response.getStatusLine().getStatusCode() == 200){
                HttpEntity res = response.getEntity();
                if (res != null) {
                    String s = EntityUtils.toString(res, "UTF-8");

//                    log.info("---------退回政务服务接口-------------");

                    JSONObject jsonObject2 = JSONObject.parseObject(s);
//                    log.info("jsonObject2的返回值：{}", jsonObject2);

//                    msg.append("接口调用：").append(json.toString()).append("\n");
                    msg.append("返回值：").append(jsonObject2).append("\n");

                    JSONObject status = jsonObject2.getJSONObject("STATUS");
//                    log.info("返回状态status-----，{}", status);

                    String code = status.getString("CODE");
//                    log.info("code------: {}", code);

                    if (Objects.equals(code,"00")) {

                        scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Success);
                        log.info("退回政务服务接口：{}",code);
                        resultFlag = true;

                    }else {
                        String text = status.getString("TEXT");
                        log.info("退回政务服务接口失败：{}",text);
                        msg.append("退回政务服务接口失败：").append(text);
                        scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
                        resultFlag = false;

                        errorLog += text;
//                        throw new BusinessException("退回政务服务接口失败："+text);
                    }

                }else {
                    scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
                    resultFlag = false;
                }
            }else {
                msg.append("退回政务服务接口失败：").append("response.getStatusLine().getStatusCode()").append("不为200");
                msg.append("接口状态：");
                msg.append(response.getStatusLine().getStatusCode());
                scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
                resultFlag = false;

                errorLog += "接口状态不为200！";
                errorLog += "为："+response.getStatusLine().getStatusCode();
//                throw new BusinessException("退回政务服务接口失败：接口状态不为200！");
            }
        }catch (Exception e){
            scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
            msg.append("退回政务服务接口失败：").append(e.getMessage());
            log.error("退回政务服务接口失败：{}", e.getMessage());
            resultFlag = false;

            scheduleJob.setFycqk(msg.toString());
            spcyScheduleJobBasicService.save(scheduleJob);

            throw new BusinessException("退回政务服务接口失败："+e.getMessage());
        }

        scheduleJob.setFycqk(msg.toString());
        spcyScheduleJobBasicService.save(scheduleJob);

        if (StringUtils.isNotBlank(errorLog)){
            throw new BusinessException("退回政务服务接口失败："+errorLog);
        }

        return resultFlag;
    }

    /**
     * 推送审评流转办理意见接口
     */
    public boolean pushSpJobLzjl(List<XzspJkApiTslzyjVo> tslzyjVoList, SpcyScheduleJobBasic scheduleJob){
        boolean resultFlag = true;

        if (scheduleJob == null){
            scheduleJob = new SpcyScheduleJobBasic();
            scheduleJob.setId(GetUuIdUtils.ReplaceUuId());
            scheduleJob.setFmethod(ScheduleConstant.Xzsp_Data_Lzjl_Method);
            scheduleJob.setFrwmc(ScheduleConstant.Xzsp_Data_Lzjl_Name); // 任务名称
            scheduleJob.setFzxsj(DateConversionUtils.DateToDays(new Date()));
            scheduleJob.setFjssj(new Date());
            scheduleJob.setFzxqk(tslzyjVoList.toString());
        }

        StringBuffer msg = new StringBuffer("0");

        String tokenString = getToken();//正式使用以后用这个
        String url = apiConstant.tssplzblyj_API;
        HttpPost httpRequest = initHttpPost(url);

        // 设置超时
        httpRequest.setConfig(requestConfig);

        /*String token = "\""+tokenString+"\"";
        String jsParam = "{" +
                "\"access_token\": "+token+"," +
                "\"param\": "+tslzyjVoList.toString()+"" +
                "}";

        JSONObject json = JSONObject.parseObject(jsParam);*/
        JSONObject json = new JSONObject();
        json.put("access_token",tokenString);
        json.put("param",tslzyjVoList);
//        log.info("{}-", json.toString());
        httpRequest.setEntity(new StringEntity(json.toString(),"UTF-8"));
        try {
            msg.append("接口调用：").append(json.toString()).append("\n");
            HttpResponse response = HttpClients.createDefault().execute(httpRequest);

            if (response.getStatusLine().getStatusCode() == 200){
                HttpEntity res = response.getEntity();
                if (res != null) {
                    String s = EntityUtils.toString(res, "UTF-8");

//                    log.info("---------推送审评流转办理意见接口-------------");

                    JSONObject jsonObject2 = JSONObject.parseObject(s);
//                    log.info("jsonObject2的返回值：{}", jsonObject2);

//                    msg.append("接口调用：").append(json.toString()).append("\n");
                    msg.append("返回值：").append(jsonObject2).append("\n");

                    JSONObject status = jsonObject2.getJSONObject("STATUS");
//                    log.info("返回状态status-----，{}", status);

                    String code = status.getString("CODE");
//                    log.info("code------: {}", code);

                    msg.append(json.toString());
                    if (Objects.equals(code,"00")) {
                        msg.append("推送审评流转办理意见接口成功：").append(code);
                        scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Success);
                        log.info("推送审评流转办理意见接口：{}",code);
                        resultFlag = true;

                    }else {
                        String text = status.getString("TEXT");
                        log.info("推送审评流转办理意见接口失败：{}",text);
                        msg.append("推送审评流转办理意见接口失败：").append(text);
                        scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
                        resultFlag = false;
                        throw new BusinessException("推送审评流转办理意见接口失败："+text);
                    }

                }else {
                    scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
                    resultFlag = false;
                }
            }else {
                msg.append("推送审评流转办理意见接口失败：").append("response.getStatusLine().getStatusCode()").append("不为200");
                msg.append("接口状态：");
                msg.append(response.getStatusLine().getStatusCode());
                scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
                resultFlag = false;
                throw new BusinessException("推送审评流转办理意见接口失败：接口状态不为200！为："+response.getStatusLine().getStatusCode());
            }
        }catch (Exception e){
            scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
            msg.append("推送审评流转办理意见接口失败：").append(e.getMessage());
            log.error("推送审评流转办理意见接口失败：{}", e.getMessage());
            resultFlag = false;

            scheduleJob.setFycqk(msg.toString());
            spcyScheduleJobBasicService.save(scheduleJob);

            throw new BusinessException("推送审评流转办理意见接口失败："+e.getMessage());
        }

        scheduleJob.setFycqk(msg.toString());
        spcyScheduleJobBasicService.save(scheduleJob);

        return resultFlag;
    }

    /**
     * 推送企业补齐补正通知接口
     */
//    @Async(value = "asyncMiddleTask")
    public boolean pushQyBqbzNotice(String sxsqjbxxid,SpcySqsxBqbzjl bqbzyj,File file,String fileName,SpcyScheduleJobBasic scheduleJob){
        boolean resultFlag = true;

        if (StringUtils.isBlank(bqbzyj.getFsffsdx()) || !bqbzyj.getFsffsdx().equals("是")){
            bqbzyj.setFdxnr("");
        }
        bqbzyj.setFbqbzsx(Optional.ofNullable(bqbzyj.getFbqbzsx()).orElse("0"));
        bqbzyj.setFyjsx(Optional.ofNullable(bqbzyj.getFyjsx()).orElse("0"));

        // 是否存在文件
        boolean isExistFile = false;
        if (StringUtils.isNotBlank(fileName)){
            isExistFile = true;
        }

        if (scheduleJob == null){
            scheduleJob = new SpcyScheduleJobBasic();
            scheduleJob.setId(GetUuIdUtils.ReplaceUuId());
            scheduleJob.setFmethod("pushQyBqbzNotice");
            scheduleJob.setFrwmc("行政审批数据-推送企业补齐补正通知接口"); // 任务名称
            scheduleJob.setFzxsj(DateConversionUtils.DateToDays(new Date()));
            scheduleJob.setFjssj(new Date());
        }

        StringBuffer msg = new StringBuffer("0");
        String errorLog = "";

        String tokenString = getToken();//正式使用以后用这个
        String url = apiConstant.tsqybqbztz_API;
        HttpPost httpRequest = initHttpPost(url);

        // 设置超时
        httpRequest.setConfig(requestConfig);

        String token = "\""+tokenString+"\"";
        String jsParam = "{" +
                "\"access_token\": "+token+"," +
                "\"param\":{" +
                "\"sxsqjbxx_id\":\""+sxsqjbxxid+"\"," +
                "\"bcxxjclyj\":\""+bqbzyj.getFbqbzyj()+"\"," +
                "\"bcxxfqr\":\""+bqbzyj.getFfqr()+"\"," +
                "\"bcxxjclsx\":\""+bqbzyj.getFbqbzsx()+"\"," +
                "\"bcxxjclyjsj\":\""+bqbzyj.getFyjsx()+"\"," +
                "\"dxnr\":\""+bqbzyj.getFdxnr()+"\"" +
                "}}";
        JSONObject json = JSONObject.parseObject(jsParam);
//        log.info("推送企业补齐补正通知接口：{}",json.toString());
        if (!isExistFile) {
            httpRequest.setEntity(new StringEntity(json.toString(), "UTF-8"));
        }

        FileInputStream fileInputStream = null;
        try {
            if (file == null) {
                fileInputStream = null;
            }else {
                fileInputStream = new FileInputStream(file);
            }
        } catch (FileNotFoundException e) {
            log.error("推送企业补齐补正通知接口，获取文件流出错，文件不存在: {}",e.getMessage());
            msg.append("【推送企业补齐补正通知接口，获取文件流出错，文件不存在】: ").append(e.getMessage());
        }

        if (isExistFile) {
            MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
            multipartEntityBuilder.setMode(HttpMultipartMode.RFC6532);   // 处理中文文件名称乱码
            multipartEntityBuilder.setCharset(Charset.forName("UTF-8"));
            multipartEntityBuilder.addBinaryBody("file", fileInputStream, ContentType.MULTIPART_FORM_DATA, fileName);
            multipartEntityBuilder.addTextBody("data", json.toString());
            HttpEntity httpEntity = multipartEntityBuilder.build();
            httpRequest.setEntity(httpEntity);
        }

        try {
            msg.append("接口调用：").append(json.toString()).append("\n");
            HttpResponse response = HttpClients.createDefault().execute(httpRequest);

            if (response.getStatusLine().getStatusCode() == 200){
                HttpEntity res = response.getEntity();
                if (res != null) {
                    String s = EntityUtils.toString(res, "UTF-8");

//                    log.info("---------推送企业补齐补正通知接口-------------");

                    JSONObject jsonObject2 = JSONObject.parseObject(s);
//                    log.info("jsonObject2的返回值：{}", jsonObject2);

//                    msg.append("接口调用：").append(json.toString()).append("\n");
                    msg.append("返回值：").append(jsonObject2).append("\n");

                    JSONObject status = jsonObject2.getJSONObject("STATUS");
//                    log.info("返回状态status-----，{}", status);

                    String code = status.getString("CODE");
//                    log.info("code------: {}", code);

                    if (Objects.equals(code,"00")) {
                        msg.append("推送企业补齐补正通知接口成功：").append(code).append("\n");
                        scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Success);
                        log.info("推送企业补齐补正通知接口：{}",code);
                        resultFlag = true;

                    }else {
                        String text = status.getString("TEXT");
                        log.info("推送企业补齐补正通知接口失败：{}",text);
                        msg.append("推送企业补齐补正通知接口失败：").append(text);
                        scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
                        resultFlag = false;
                        errorLog += text;
//                        throw new BusinessException("推送企业补齐补正通知接口失败："+text);
                    }

                }else {
                    scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
                    resultFlag = false;
                }
            }else {
                msg.append("推送企业补齐补正通知接口失败：").append("response.getStatusLine().getStatusCode()").append("不为200;");
                msg.append("接口状态：");
                msg.append(response.getStatusLine().getStatusCode());
                scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
                resultFlag = false;
                errorLog += "接口状态不为200！";
                errorLog += "为："+response.getStatusLine().getStatusCode();
//                throw new BusinessException("推送企业补齐补正通知接口失败：接口状态不为200！");
            }
        }catch (Exception e){
            scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
            msg.append("推送企业补齐补正通知接口失败：").append(e.getMessage());
            log.error("推送企业补齐补正通知接口失败：{}", e.getMessage());
            resultFlag = false;

            scheduleJob.setFycqk(msg.toString());
            spcyScheduleJobBasicService.save(scheduleJob);
            throw new BusinessException("推送企业补齐补正通知接口失败："+e.getMessage());
        }

        scheduleJob.setFycqk(msg.toString());
        spcyScheduleJobBasicService.save(scheduleJob);

        if (StringUtils.isNotBlank(errorLog)){
            throw new BusinessException("推送企业补齐补正通知接口失败: "+errorLog);
        }

        return resultFlag;
    }


    /**
     * 推送企业补充整改通知接口
     */
//    @Async(value = "asyncMiddleTask")
    public boolean pushQyBcZgNotice(String sxsqjbxxid,SpcySqsxBczgjl bczgjl,File file,String fileName,SpcyScheduleJobBasic scheduleJob){
        boolean resultFlag = true;

        if (StringUtils.isBlank(bczgjl.getFsffsdx()) || !bczgjl.getFsffsdx().equals("是")){
            bczgjl.setFdxnr("");
        }
        bczgjl.setFyjsx(Optional.ofNullable(bczgjl.getFyjsx()).orElse("0"));
        bczgjl.setFzgsx(Optional.ofNullable(bczgjl.getFzgsx()).orElse("0"));

        // 是否存在文件
        boolean isExistFile = false;
        if (StringUtils.isNotBlank(fileName)){
            isExistFile = true;
        }

        if (scheduleJob == null){
            scheduleJob = new SpcyScheduleJobBasic();
            scheduleJob.setId(GetUuIdUtils.ReplaceUuId());
            scheduleJob.setFmethod("pushQyBcZgNotice");
            scheduleJob.setFrwmc("行政审批数据-推送企业补充整改通知接口"); // 任务名称
            scheduleJob.setFzxsj(DateConversionUtils.DateToDays(new Date()));
            scheduleJob.setFjssj(new Date());
        }

        StringBuffer msg = new StringBuffer("0");
        String errorLog = "";

        String tokenString = getToken();//正式使用以后用这个
        String url = apiConstant.tsqybczgtz_API;
        HttpPost httpRequest = initHttpPost(url);

        // 设置超时
        httpRequest.setConfig(requestConfig);

        String token = "\""+tokenString+"\"";
        String jsParam = "{" +
                "\"access_token\": "+token+"," +
                "\"param\":{" +
                "\"sxsqjbxx_id\":\""+sxsqjbxxid+"\"," +
                "\"zgfrq\":\""+bczgjl.getFfqr()+"\"," +
                "\"zgyj\":\""+bczgjl.getFzgyj()+"\"," +
                "\"zgsx\":\""+bczgjl.getFzgsx()+"\"," +
                "\"zgyjsj\":\""+bczgjl.getFyjsx()+"\"," +
                "\"dxnr\":\""+bczgjl.getFdxnr()+"\"" +
                "}}";

        JSONObject json = JSONObject.parseObject(jsParam);
//        log.info("推送企业补充整改通知接口：{}",json.toString());
        if (!isExistFile) {
            httpRequest.setEntity(new StringEntity(json.toString(), "UTF-8"));
        }

        FileInputStream fileInputStream = null;
        try {
            if (file == null) {
                fileInputStream = null;
            }else {
                fileInputStream = new FileInputStream(file);
            }
        } catch (FileNotFoundException e) {
            log.error("推送企业补充整改通知接口，获取文件流出错，文件不存在: {}",e.getMessage());
            msg.append("【推送企业补充整改通知接口，获取文件流出错，文件不存在】: ").append(e.getMessage());
        }

        if (isExistFile) {
            MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
            multipartEntityBuilder.setMode(HttpMultipartMode.RFC6532);   // 处理中文文件名称乱码
            multipartEntityBuilder.setCharset(Charset.forName("UTF-8"));
            multipartEntityBuilder.addBinaryBody("file", fileInputStream, ContentType.MULTIPART_FORM_DATA, fileName);
            multipartEntityBuilder.addTextBody("data", json.toString());
            HttpEntity httpEntity = multipartEntityBuilder.build();
            httpRequest.setEntity(httpEntity);
        }

        try {
            msg.append("接口调用：").append(json.toString()).append("\n");
            HttpResponse response = HttpClients.createDefault().execute(httpRequest);

            if (response.getStatusLine().getStatusCode() == 200){
                HttpEntity res = response.getEntity();
                if (res != null) {
                    String s = EntityUtils.toString(res, "UTF-8");

//                    log.info("---------推送企业补充整改通知接口-------------");

                    JSONObject jsonObject2 = JSONObject.parseObject(s);
//                    log.info("jsonObject2的返回值：{}", jsonObject2);

//                    msg.append("接口调用：").append(json.toString()).append("\n");
                    msg.append("返回值：").append(jsonObject2).append("\n");

                    JSONObject status = jsonObject2.getJSONObject("STATUS");
//                    log.info("返回状态status-----，{}", status);

                    String code = status.getString("CODE");
//                    log.info("code------: {}", code);
                    msg.append("url：").append(json.toString()).append("\n");
                    if (Objects.equals(code,"00")) {
                        msg.append("推送企业补充整改通知接口成功：").append(code).append("\n");
                        scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Success);
                        log.info("推送企业补充整改通知接口：{}",code);
                        resultFlag = true;

                    }else {
                        String text = status.getString("TEXT");
                        log.info("推送企业补充整改通知接口失败：{}",text);
                        msg.append("推送企业补充整改通知接口失败：").append(text);
                        scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
                        resultFlag = false;
                        errorLog += text;
//                        throw new BusinessException("推送企业补充整改通知接口失败："+text);
                    }

                }else {
                    scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
                    resultFlag = false;
                }
            }else {
                msg.append("推送企业补充整改通知接口失败：").append("response.getStatusLine().getStatusCode()").append("不为200");
                msg.append("接口状态：");
                msg.append(response.getStatusLine().getStatusCode());
                scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
                resultFlag = false;

                errorLog += "接口状态不为200！";
                errorLog += "为："+response.getStatusLine().getStatusCode();
//                throw new BusinessException("推送企业补充整改通知接口失败：接口状态不为200！");
            }
        }catch (Exception e){
            scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
            msg.append("推送企业补充整改通知接口失败：").append(e.getMessage());
            log.error("推送企业补充整改通知接口失败：{}", e.getMessage());
            resultFlag = false;

            scheduleJob.setFycqk(msg.toString());
            spcyScheduleJobBasicService.save(scheduleJob);

            throw new BusinessException("推送企业补充整改通知接口失败："+e.getMessage());
        }

        scheduleJob.setFycqk(msg.toString());
        spcyScheduleJobBasicService.save(scheduleJob);

        if (StringUtils.isNotBlank(errorLog)){
            throw new BusinessException("推送企业补充整改通知接口失败: "+errorLog);
        }

        return resultFlag;
    }

    /**
     * 推送审评中心撤件意见接口
     * @param sxsqjbxxid
     * @param loginName 撤件人账号
     * @param spzxyj
     * @param tjsj
     */
    public boolean pushSpzxCjyj(String sxsqjbxxid,String spzxyj,String tjsj,String loginName,SpcyScheduleJobBasic scheduleJob){
        boolean resultFlag = true;

        if (scheduleJob == null){
            scheduleJob = new SpcyScheduleJobBasic();
            scheduleJob.setId(GetUuIdUtils.ReplaceUuId());
            scheduleJob.setFmethod("pushSpzxCjyj");
            scheduleJob.setFrwmc("行政审批数据-推送审评中心撤件意见接口"); // 任务名称
            scheduleJob.setFzxsj(DateConversionUtils.DateToDays(new Date()));
            scheduleJob.setFjssj(new Date());
        }

        StringBuffer msg = new StringBuffer("0");
        String errorLog = "";

        String tokenString = getToken();//正式使用以后用这个
        String url = apiConstant.tsspzxcjyj_API;
        HttpPost httpRequest = initHttpPost(url);

        // 设置超时
        httpRequest.setConfig(requestConfig);

        String token = "\""+tokenString+"\"";
        String jsParam = "{" +
                "\"access_token\": "+token+"," +
                "\"param\":{" +
                "\"sxsqjbxx_id\":\""+sxsqjbxxid+"\"," +
                "\"spzxyj\":\""+spzxyj+"\"," +
                "\"username\":\""+loginName+"\"" +
                "}}";
        JSONObject json = JSONObject.parseObject(jsParam);
        httpRequest.setEntity(new StringEntity(json.toString(),"UTF-8"));
        try {
            msg.append("接口调用：").append(json.toString()).append("\n");
            HttpResponse response = HttpClients.createDefault().execute(httpRequest);

            if (response.getStatusLine().getStatusCode() == 200){
                HttpEntity res = response.getEntity();
                if (res != null) {
                    String s = EntityUtils.toString(res, "UTF-8");

//                    log.info("---------推送审评中心撤件意见接口-------------");

                    JSONObject jsonObject2 = JSONObject.parseObject(s);
//                    log.info("jsonObject2的返回值：{}", jsonObject2);

//                    msg.append("接口调用：").append(json.toString()).append("\n");
                    msg.append("返回值：").append(jsonObject2).append("\n");

                    JSONObject status = jsonObject2.getJSONObject("STATUS");
//                    log.info("返回状态status-----，{}", status);

                    String code = status.getString("CODE");
//                    log.info("code------: {}", code);

                    if (Objects.equals(code,"00")) {
                        msg.append("推送审评中心撤件意见接口成功：").append(code);
                        scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Success);
                        log.info("推送审评中心撤件意见接口：{}",code);
                        resultFlag = true;

                    }else {
                        String text = status.getString("TEXT");
                        log.info("推送审评中心撤件意见接口失败：{}",text);
                        msg.append("推送审评中心撤件意见接口失败：").append(text);
                        scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
                        resultFlag = false;

                        errorLog += text;
//                        throw new BusinessException("推送审评中心撤件意见接口失败："+text);
                    }

                }else {
                    scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
                    resultFlag = false;
                }
            }else {
                msg.append("退回政务服务接口失败：").append("response.getStatusLine().getStatusCode()").append("不为200");
                msg.append("接口状态：");
                msg.append(response.getStatusLine().getStatusCode());
                scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
                resultFlag = false;

                errorLog += "接口状态不为200！";
                errorLog += "为："+response.getStatusLine().getStatusCode();
//                throw new BusinessException("推送审评中心撤件意见接口失败：接口状态不为200！");
            }
        }catch (Exception e){
            scheduleJob.setFzxzt(ScheduleConstant.Job_Basic_Error);
            msg.append("推送审评中心撤件意见接口失败：").append(e.getMessage());
            log.error("推送审评中心撤件意见接口失败：{}", e.getMessage());
            resultFlag = false;

            scheduleJob.setFycqk(msg.toString());
            spcyScheduleJobBasicService.save(scheduleJob);

            throw new BusinessException("推送审评中心撤件意见接口失败："+e.getMessage());
        }

        scheduleJob.setFycqk(msg.toString());
        spcyScheduleJobBasicService.save(scheduleJob);

        if (StringUtils.isNotBlank(errorLog)){
            throw new BusinessException("推送审评中心撤件意见接口失败："+errorLog);
        }

        return resultFlag;
    }
}
